<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="src/all.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
        .tb-img-circle {
            width: 40px;
            height: 40px;
            cursor: zoom-in;
            border-radius: 50%;
            border: 2px solid #dddddd;
        }
        #test+.layui-table-view .layui-table-body tbody>tr>td>.layui-table-cell {
            height: 70px;
            line-height: 48px;
        }
        #test+.layui-table-view .layui-table-body tbody>tr>td {
            padding: 0;
        }
        .layui-table-cell {
            height: auto;
        }
    </style>
</head>

<body>
    <div class="layui-fluid margin-top">
        <div class="layui-card">
            <div class="layui-card-body">
                <table class="layui-hide" id="test" lay-filter="test"></table>
            </div>
        </div>
    </div>
    <script type="text/html" id="toolbarDemo">
        <form action="layui-form" lay-filter='form'>
          <div class="layui-btn-container cl">
          <button class="layui-btn layui-btn-sm layui-top-add" lay-event="import">审核通过</button>
          <button class="layui-btn layui-btn-sm layui-top-danger" lay-event="del">删除</button>
          <input type="checkbox" id='status' name="sex" value="1" lay-skin="switch" lay-text="已导入|未导入" lay-filter="sexDemo">
        </div>
       </form>
     
  </script>
    <script type="text/html" id="barDemo">
        <a class="layui-link layui-btn-xs" lay-event="edit">修改部门</a>
        <a class="layui-link  layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script src="layuiadmin/modules/axios.min.js"></script>
    <script src="layuiadmin/layui/layui.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script>
    layui.config({
        base: 'layuiadmin/modules/'
    }).use(['main', 'notice', 'form'], function() {
        var table = layui.table,
            $ = layui.jquery,
            notice = layui.notice,
            axios = layui.main
        form = layui.form;
        table.render({
            elem: '#test',
            url: '${cls.getrooturl()}?type=sel&tabid=${tabid}&mid=${mid}&job=${job}&tbname=${tbname}&T=待导入人员sql',
            where: {
                status: 0
            },
            height: 'full-40',
            cellMinWidth: 120,
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            title: '用户数据表',
            cols: [
                [
                    { type: 'checkbox', fixed: 'left' },
                    { field: 'ids', width: 80, title: 'ids', sort: true, hide: true },
                    { field: 'stay_name', title: '姓名', align: 'center', sort: true },
                    { field: 'stay_dept', title: '部门', align: 'center', sort: true },
                    { field: 'stay_jobnumber', title: '账号', align: 'center', sort: true },
                    { field: 'stay_time', title: '登记时间', align: 'center', sort: true },
                    { field: 'stay_qw_code', title: '微信用户编号', align: 'center', sort: true },
                    { field: 'stay_id_code', title: '身份证号', align: 'center', sort: true },
                    {
                        field: 'stay_status',
                        title: '状态',
                        align: 'center',
                        sort: true,
                        templet: function(d) {

                            if (d.stay_status == 0) {
                                return '<button class="layui-btn layui-btn-normal  layui-btn-sm layui-bg-red" > 未导入</button>'
                            } else {
                                return '<button class="layui-btn layui-btn-normal  layui-btn-sm layui-bg-green" > 已导入</button>'

                            }
                        }
                    },
                    {
                        field: 'stay_avatar',
                        title: '头像',
                        templet: function(d) {
                            if (!d.stay_avatar) {
                                return `<img class="tb-img-circle" src='/pic/moren.png' />`
                            }
                            return `<img class="tb-img-circle" src='${d.stay_avatar}' />`
                        }
                    },
                    { field: 'createdate', align: 'center', title: '时间', width: 120, sort: true },
                    { fixed: 'right', align: 'center', title: '操作', toolbar: '#barDemo', width: 140 }
                ]
            ],
            id: 'table',
            page: true
        });
        form.on('switch(sexDemo)', function(data) {
            let t_or_f = data.elem.checked ? "1" : "0"
            modifyUser(t_or_f, data.elem.checked)
        });

        function modifyUser(status, f) {
            table.reload('table', {
                where: {
                    status: status
                }
            })
            $('#status').prop('checked', f)
            form.render()
            // form.val('form', {
            //     sex: t_or_f
            // })
        }
        //头工具栏事件
        table.on('toolbar(test)', function(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'import':
                    var data = checkStatus.data;
                    if (data.length <= 0) { layer.msg('请选择数据'); return };

                    let ids = [];
                    for (var i = 0; i < data.length; i++) {
                        let obj = data[i]
                        ids.push(obj.ids);
                    }
                    layer.confirm('确认导入吗', function(i) {
                        axios({
                            url: '/api/AcceptCreatingUserRequests',
                            method: 'post',
                            data: Qs.stringify({
                                ids: ids.join(','),
                                perms: '40cd419f-74aa-4afa-abc6-91fcc01727d2'
                            })
                        }).then(data => {
                            table.reload('table', {}, false)
                            layer.close(i)
                        })
                    })
                    break;
                case 'add':
                    layer.open({
                        type: 2,
                        zIndex: layer.zIndex, //重点1
                        title: '新建',
                        shadeClose: true,
                        // shade: true,
                        maxmin: false, //开启最大化最小化按钮
                        area: ['90%', '90%'],
                        content: '${cls.getrooturl()}?type=addshow&tabid=${tabid}&mid=${mid}&job=${job}&tbname=${tbname}',
                        success: function(layero, index) {
                            var iframeWindow = window['layui-layer-iframe' + index]
                            var submitID = 'LAY-user-back-submit'
                            var input = layero.find('iframe').contents().find('#' + submitID);
                        },
                        end: function() {
                            table.reload('table', {}, false)
                        }

                    });
                    break;
                case 'edit':
                    var data = checkStatus.data;
                    if (data.length != 1) { notice.msg('请选择一条数据', { icon: 2 }); return }
                    layer.open({
                        type: 2,
                        zIndex: layer.zIndex, //重点1
                        title: '编辑',
                        shadeClose: true,
                        maxmin: false, //开启最大化最小化按钮
                        area: ['400px', '400px'],
                        content: '${cls.getrooturl()}?type=addshow&id=' + data[0].ids + '&tabid=${tabid}&mid=${mid}&job=${job}&tbname=${tbname}',
                        success: function(layero, index) {

                        },
                        end: function() {
                            table.reload('table', {}, false)
                        }
                    });
                    break;
                case 'del':
                    var data = checkStatus.data;
                    if (data.length < 1) { notice.msg('请选择数据', { icon: 2 }); return }
                    let idsarr = [];
                    for (var i = 0; i < data.length; i++) {
                        let obj = data[i]
                        idsarr.push(obj.ids);
                    }
                    layer.confirm('真的删除选中数据么', function(ler) {
                        axios({
                            url: '${cls.getrooturl()}?type=del&id=' + idsarr.join(',') + '&mid=${mid}&tabid=${tabid}&job=${job}&tbname=${tbname}',
                            method: 'post',
                        }).then(data => {
                            table.reload('table', {}, false)
                            layer.close(ler)
                        })
                    });
                    break;
            };
        });
        //监听行工具事件
        table.on('tool(test)', function(obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function(index) {
                    axios({
                        url: '$cls.getrooturl()?type=del&id=' + data.ids + '&mid=$!{mid}&tabid=$!{tabid}&job=${job}&tbname=${tbname}',
                        method: 'post',
                        data: $("form").serialize(),
                    }).then(data => {

                        table.reload('table', {}, false)
                        layer.close(index)

                    })

                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 2,
                    zIndex: layer.zIndex, //重点1
                    title: '编辑',
                    shadeClose: true,
                    maxmin: false, //开启最大化最小化按钮
                    area: ['90%', '90%'],
                    content: '${cls.getrooturl()}?type=addshow&id=' + data.ids + '&tabid=${tabid}&mid=${mid}&job=${job}&tbname=${tbname}',
                    success: function(layero, index) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                        var name = 'dept'
                        var id = 'bid'
                        var dept_name = layero.find('iframe').contents().find('#' + name);
                        var dept_id = layero.find('iframe').contents().find('#' + id);
                        $(dept_name).val(data.stay_dept)
                        $(dept_id).val(data.stay_deptid)
                    },
                    end: function() {
                        table.reload('table', {}, false)
                    }
                });
            }
        });

    });
    </script>
</body>

</html>